import request from '@/utils/request.js'

export const selectModel = ref(null)
export const selectWorkflow = ref(null)
export const switchDeepThinking = ref(false)
export const supportDeepThinking = ref(false)
export const supportImageUpload = ref(false)
export const supportFileUpload = ref(false)
export const canSendFlag = ref(true)
export const isPreviewFlag = ref(false)
export const canSelectModelFlag = ref(true)
export const llmModelData = ref([])
export const workflowData = ref([])

// 大模型选择
export const currentSelectType = ref("llmModel")

// 预览模式下的数据
export const previewReqData = ref({})

export const messages = ref([
    {text: 'Hi~ 我是你身边的智能助手，可以为你答疑解惑、精读文档、尽情创作，让AI助你轻松工作，多点生活', isUser: false, isTips: true}
])

// 今天的历史数据
export const historyData = ref([])
// 本月的历史数据
export const historyDataMonth = ref([])
// 更早的历史数据
export const historyDataEarlier = ref([])
export const requestAnswerGroupCode = ref(null)
export const requestAnswerGroupName = ref(null)
export const messagesRef = ref(null)

export const aiAppId = ref(null)

export function initNewChat() {
    messages.value = [
        {
            text: 'Hi~ 我是你身边的智能助手，可以为你答疑解惑、精读文档、尽情创作，让AI助你轻松工作，多点生活',
            isUser: false,
            isTips: true,
            isReaction: false
        }
    ]
    requestAnswerGroupCode.value = null
    requestAnswerGroupName.value = null
}

export function getSendHistory() {
    return request({
        url: '/tool/aiSendHistory/listAll',
        method: 'post',
        data: {
            appId: aiAppId.value
        }
    })
}

export function getSendHistoryByGroupCode(groupCode) {
    return request({
        url: '/tool/aiSendHistory/listByGroupCode/' + groupCode,
        method: 'get'
    })
}

export function deleteSendHistoryByCode(code) {
    return request({
        url: '/tool/aiSendHistory/deleteByCode/' + code,
        method: 'delete'
    })
}

export function updateSendHistoryGroupNameByCode(groupCode, newGroupName) {
    return request({
        url: '/tool/aiSendHistory/updateGroupNameByCode',
        method: 'put',
        data: {
            groupCode,
            newGroupName
        }
    })
}

export function initHistoryData() {
    historyData.value = []
    historyDataMonth.value = []
    historyDataEarlier.value = []
    getSendHistory().then(resp => {
        if (resp.data !== null) {
            resp.data.forEach(item => {
                console.log(item.type)
                if (item.type === 0) {
                    historyData.value.push(item)
                } else if (item.type === 1) {
                    historyDataMonth.value.push(item)
                } else if (item.type === 2) {
                    historyDataEarlier.value.push(item)
                }
            })
        }
    })
}

export function sendMessageNew(data) {
    return request({
        url: '/tool/ai/sendMessage',
        method: 'post',
        data: data
    })
}



